import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    shopcar: [],
  },
  getters: {},
  mutations: {
    add(state, val) {
      let flag = false;
      state.shopcar.forEach((i) => {
        if (i.spuId == val.spuId) {
          i.store_nums++;
          flag = true;
        }
      });
      if (flag == false) {
        val.store_nums = 1;
        val.status = false;
        //初始状态 没选中 加一个状态代表他有没有选中
        state.shopcar.push(val);
      }
    },
    checkall(state, checked) {
      state.shopcar.forEach((i) => {
        i.status = checked;
      });
    },
    //把全选的状态传过来 是true 都变成true 是false 都变成false
    removeall(state) {
      state.shopcar = state.shopcar.filter((i) => i.status == false);
    },
    //把状态是false 的留下来
  },
  actions: {},
  modules: {},
});
